<template>
	<view>
		<!-- 巡检故障首页 -->
		<view class="Inspection_io">

			<view class="header_flex">
				<view @tap="headerTap(1)" :class="{'header_text_click':headerTapNum==1}" class="header_text">日程
				</view>
				<view @tap="headerTap(2)" :class="{'header_text_click':headerTapNum==2}" class="header_text">隐患
				</view>
			</view>

			<view v-if="headerTapNum==1" style="padding: 0 20rpx;">
				<view class="Inspection_header">
					<view class="">
						<uni-calendar :start-date="currentDate()" @monthSwitch="monthSwitch" :mark="false" :insert="true" :selected="selected"
							@change="change" />
					</view>
				</view>
				<scroll-view scroll-y="true" class="scroll-Y">
					<view class="Inspection_center">
						<view class="Inspection_flex" @tap="inspectionTap(item)" :key="index"
							v-for="(item,index) in inspectionData">
							<view class="">
								<view class="Inspection_title">
									{{item.plan_name}}
								</view>
								<view class="Inspection_text">

									<view v-if="item.inspection_type == '按天'" class="">
										每隔{{item.plan_data}}天巡检
									</view>
									<view v-if="item.inspection_type == '按周'" class="">
										每周{{item.plan_data}}巡检
									</view>
									<view v-if="item.inspection_type == '按月'" class="">
										每月{{item.plan_data}}号巡检
									</view>
								</view>

							</view>
							<view v-if="isdayDta" class="Inspection_btn" style="">
								进入
							</view>

						</view>

					</view>
				</scroll-view>
			</view>
			<view v-if="headerTapNum==2" style="padding: 0 20rpx;">
				<scroll-view scroll-y="true" class="scroll-YTwo">
					<view class="Inspection_center">
						<view class="Inspection_flex" @tap="faultTap(item)" :key="index"
							v-for="(item,index) in faultData">
							<view class="">
								<view class="Inspection_title">
									{{item.inspectionPlanName || ''}}
								</view>
								<view class="Inspection_text2">
									{{item.pitfallCorrectionContent || ''}}
								</view>
								<view class="Inspection_times">
									{{item.inspectionDate || ''}}
								</view>
							</view>
							<view class="" style="color: #007aff;font-size: 30rpx;">
								{{item.pitfallCorrection =='Y'? "已处理":'未处理'}}
							</view>

						</view>

					</view>
				</scroll-view>

			</view>

		</view>
	</view>
</template>

<script>
	import config from '@/config'
	import {
		getMyTaskList,
		getPitfallListTable,
		myTaskRecordByMonth
	} from '@/apis/modules/inspectionApp';
	export default {
		data() {
			return {
				baseUrl: config.baseUrl,
				selected: [],
				inspectionData: [],
				headerTapNum: 1,
				faultData: [],
				timesData: '',
				dayDta:'',
				isdayDta:true
			}
		},
		onLoad(options) {
			this.todayDate()
			this.mobthDate()
		},
		methods: {
			currentDate() {
				// return new Date().toLocaleDateString();
			},
			myTaskRecordByMonthFun(month) {
				myTaskRecordByMonth({
					inspectionMonth: month
				}).then((res) => {
					let arr = []
					for(let item of res.data){
						arr.push({
							date:item.inspection_date,
							info:'有任务'
						})
					}
					console.log(arr,'arrarrarr')
					
					this.selected = arr
				})
			},
			mobthDate() {
				const now = new Date();
				const year = now.getFullYear();
				const month = (now.getMonth() + 1).toString().padStart(2, '0');
				const day = now.getDate().toString().padStart(2, '0');
				let monthData = `${year}-${month}`
				this.myTaskRecordByMonthFun(monthData)
			},
			todayDate() {
				const now = new Date();
				const year = now.getFullYear();
				const month = (now.getMonth() + 1).toString().padStart(2, '0');
				const day = now.getDate().toString().padStart(2, '0');
				this.timesData = `${year}-${month}-${day}`
				this.dayDta = `${year}-${month}-${day}`
				this.inspectionList(`${year}-${month}-${day}`)
			},
			monthSwitch(e){
				let monthData = `${e.year}-${e.month}`
				this.myTaskRecordByMonthFun(monthData)
			},
			//改日期
			change(e) {
				this.timesData = e.fulldate
				if(this.dayDta == this.timesData){
					this.isdayDta = true
				} else {
					this.isdayDta = false
				}
				this.inspectionList(e.fulldate)
			},
			//巡检列表
			inspectionList(e) {
				let parms = {
					inspectionUserId: this.profile.userId,
					inspectionDate: e
				}
				getMyTaskList(parms).then((res) => {
					console.log(res)
					this.inspectionData = res.data
				})

			},
			//巡检故障
			faultList() {
				let parms = {
					pageNum: 1,
					pageSize: 10,
				}
				getPitfallListTable(parms).then((res) => {
					this.faultData = res.rows
				})
			},
			//巡检故障切换
			headerTap(type) {
				this.headerTapNum = type

				if (this.headerTapNum == 1) {
					this.todayDate()
				}
				if (this.headerTapNum == 2) {
					this.faultList()
				}

			},
			//巡检列表点击进入巡检页
			inspectionTap(item) {
				if(this.isdayDta){
					console.log(item.inspection_id)
					uni.navigateTo({
						url: `/pagesB/inspectionApp/InspectionCode?id=${item.inspection_id}&times=${this.timesData}&planId=${item.inspection_plan_id}`
					});
				}
		
			},
			//故障列表点击进入巡检页
			faultTap(item) {
				uni.navigateTo({
					url: '/pagesB/inspectionApp/dangerHandling?id=' + item.inspectionRecordId
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.Inspection_io {
		width: 100%;
		background-color: #eff3f6;
		overflow: hidden;

		.scroll-Y {
			height: calc(49vh);
		}

		.scroll-YTwo {
			height: calc(84vh);
		}

		.header_flex {
			display: flex;
			border: 1rpx solid #007aff;
			border-radius: 10rpx;
			width: 90%;
			margin: 10px auto;
			font-size: 30rpx;

			.header_text {
				width: 50%;
				text-align: center;
				color: #007aff;
				padding: 10rpx 30rpx;
			}

			.header_text_click {
				padding: 10rpx 30rpx;
				background-color: #007aff;
				color: white;
				// margin: 10rpx;

			}
		}



		.Inspection_header {
			background-color: white;
			border-radius: 10rpx;
			overflow: hidden;


		}

		.Inspection_flex {
			background-color: white;
			padding: 20rpx 30rpx 0 30rpx;
			margin-top: 10rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-radius: 10rpx;
			border-top: 1px solid gainsboro;

			.Inspection_title {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 14px;
				color: #4B5156;
				line-height: 24px;

				font-style: normal;
				text-transform: none;
			}

			.Inspection_text2 {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #007AFC;
				line-height: 48rpx;
				font-style: normal;
				text-transform: none;
			}

			.Inspection_times {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #B9BAC8;
				line-height: 48rpx;
				font-style: normal;
				text-transform: none;
			}

			.Inspection_text {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 11px;
				color: #74B7FF;
				line-height: 24px;

				font-style: normal;
				text-transform: none;
			}

			.Inspection_btn {
				padding: 5rpx 20rpx;
				background: linear-gradient(90deg, #007AFC 0%, #75CCFA 100%);
				border-radius: 94rpx 94rpx 94rpx 94rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 24rpx;
				color: #FFFFFF;
				line-height: 48rpx;
				text-align: center;
				font-style: normal;
				text-transform: none;
			}

		}
	}
</style>